package org.example.controller;

import com.aliyun.oss.OssInputUtil;
import lombok.extern.slf4j.Slf4j;
import org.example.anno.Log;
import org.example.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@Slf4j
/**
 * 文件上传
 */
public class UploadController {

    @Autowired
    private OssInputUtil ossInputUtil;
    @Log
    @PostMapping("/upload")
    public Result upload(MultipartFile image) throws IOException {
        log.info("文件上传开始，上传的文件为：{}",image.getOriginalFilename());
        String url = ossInputUtil.uploadFile(image);
        return Result.success(url);
    }
}
